package org.qiancizhan.Mapper;

import org.qiancizhan.Config.MySQL;
import org.qiancizhan.Model.POJO.LanguagePOJO;

import java.util.List;

public class LanguageMapper {
    private final MySQL mySQL = MySQL.getInstance();
    public List<LanguagePOJO> getAllLanguage() {
        return mySQL.executeQuery("SELECT * FROM `language_code`",rs -> {
            LanguagePOJO languagePOJO = new LanguagePOJO();
            languagePOJO.setLang(rs.getString("lang"));
            languagePOJO.setLangCode(rs.getString("langCode"));
            return languagePOJO;
        });
    }

    public LanguagePOJO getLanguageByLang(String lang) {
        List<LanguagePOJO> res = mySQL.executeQuery(String.format("SELECT * FROM `language_code` WHERE lang = '%s'",lang),rs -> {
            LanguagePOJO languagePOJO = new LanguagePOJO();
            languagePOJO.setLang(rs.getString("lang"));
            languagePOJO.setLangCode(rs.getString("langCode"));
            return languagePOJO;
        });
        return res.size() == 0 ? null : res.get(0);
    }
}
